package com.ruoyi.modules.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.modules.service.INumRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.modules.domain.DyAppUser;
import com.ruoyi.modules.service.IDyAppUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 抖音app用户Controller
 *
 * @author ruoyi
 * @date 2022-01-22
 */
@Api(tags = "后台接口 - 抖音app用户")
@RestController
@RequestMapping("/backstage/dyAppUser")
public class DyAppUserController extends BaseController {
    @Autowired
    private IDyAppUserService dyAppUserService;


    /**
     * 查询抖音app用户列表
     */
    @PreAuthorize("@ss.hasPermi('modules:user:list')")
    @ApiOperation(value="抖音app用户列表", notes="抖音app用户列表")
    @GetMapping("/list")
    public TableDataInfo list(DyAppUser dyAppUser) {

        startPage();
        List<DyAppUser> list = dyAppUserService.listDyAppUser(dyAppUser.getAgentUserId(), dyAppUser.getNickName(), dyAppUser.getCode());
        return getDataTable(list);
    }

    /**
     * 导出抖音app用户列表
     */
    @PreAuthorize("@ss.hasPermi('modules:user:export')")
    @Log(title = "抖音app用户", businessType = BusinessType.EXPORT)
    @ApiOperation(value="导出表格", notes="导出表格")
    @GetMapping("/export")
    public AjaxResult export(DyAppUser dyAppUser) {
        List<DyAppUser> list = dyAppUserService.list(new QueryWrapper<>(dyAppUser));
        ExcelUtil<DyAppUser> util = new ExcelUtil<DyAppUser>(DyAppUser.class);
        return util.exportExcel(list, "抖音app用户数据");
    }

    /**
     * 获取抖音app用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('modules:user:query')")
    @ApiOperation(value="抖音app用户详情", notes="抖音app用户列情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(dyAppUserService.getById(id));
    }

    /**
     * 新增抖音app用户
     */
    @PreAuthorize("@ss.hasPermi('modules:user:add')")
    @Log(title = "抖音app用户", businessType = BusinessType.INSERT)
    @ApiOperation(value="抖音app用户新增", notes="抖音app用户新增")
    @PostMapping
    public AjaxResult add(@RequestBody DyAppUser dyAppUser) {
        return toAjax(dyAppUserService.save(dyAppUser));
    }

    /**
     * 修改抖音app用户
     */
    @PreAuthorize("@ss.hasPermi('modules:user:edit')")
    @Log(title = "抖音app用户", businessType = BusinessType.UPDATE)
    @ApiOperation(value="抖音app用户修改", notes="抖音app用户修改")
    @PutMapping
    public AjaxResult edit(@RequestBody DyAppUser dyAppUser) {
        return toAjax(dyAppUserService.updateById(dyAppUser));
    }

    /**
     * 删除抖音app用户
     */
    @PreAuthorize("@ss.hasPermi('modules:user:remove')")
    @Log(title = "抖音app用户", businessType = BusinessType.DELETE)
    @ApiOperation(value="抖音app用户删除", notes="抖音app用户删除")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dyAppUserService.removeByIds(Arrays.asList(ids)));
    }

}
